import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:神奇数
 * User: wangxin
 * Date: 2024-08-02
 * Time: 18:45
 */
public class test3 {
    public static boolean isPrime(int[] arr){
        for(int i = 0;i < arr.length;i++){
            if(arr[i] == 0){
                break;
            }
            int sqrt = (int)Math.sqrt(arr[i]);
            for(int j = 3;j < sqrt;j++){
                if(arr[i] % 2 != 0 && arr[i] % j != 0 ){
                    return  true;
                }
            }
        }
        return false;
    }
    public static boolean split(int cur){
        int n = 0;
        int tar = cur;
        while(tar > 0){
           tar /= 10;
           n++;
        }
        int[] arr1 = new int[n];
        int[] arr2 = new int[1000];
        for(int i = 0;i < arr1.length;i++){
            arr1[i] = cur % 10;
            cur /= 10;
        }
        int i = 0;
        while(i < arr2.length ){
            for(int c = 0; c < arr1.length;c++ ){
                if(arr1[c] == 0){
                    continue;
                }
                for(int d = 0;d < arr1.length;d++){
                    if(c == d ){
                        continue;
                    }
                    arr2[i] = arr1[c] * 10 + arr1[d];
                    i++;
                }
            }
            break;
        }
        if(isPrime(arr2)){
            return true;
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int[] arr = new int[b-a+1];
        for(int i = 0;i < arr.length;i++){
            arr[i] = a;
            a++;
        }
        int count = 0;
        for(int i = 0;i < arr.length;i++){

           if(split(arr[i])){
               count++;
           }
        }
        System.out.println(count);
    }
}
